﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows;
using vmlModel.Entities;
using vmlModel;

namespace XAMLFactory
{
    public class SimpleShapesBuilder
    {
        public Rectangle CreateRectangle(vmlModel.Entities.vmlRect srcRec)
        {

            Rectangle MainShape = new Rectangle();
            Canvas.SetTop(MainShape, srcRec.MarginTop);
            Canvas.SetLeft(MainShape, srcRec.MarginLeft);
            Canvas.SetZIndex(MainShape, srcRec.Zindex);
            MainShape.Width = srcRec.Width;
            MainShape.Height = srcRec.Height;


            MainShape.Fill = new SolidColorBrush(srcRec.FillColor);
            MainShape.Stroke = new SolidColorBrush(srcRec.StrokeColor);
            MainShape.StrokeThickness = srcRec.StrokeWeight;
            if (srcRec.Stroke != null)
            {
                if (srcRec.Stroke.LiveAtrrs.Contains("weight")) MainShape.StrokeThickness = srcRec.Stroke.Weight;
                if (srcRec.Stroke.LiveAtrrs.Contains("color")) MainShape.Stroke = new SolidColorBrush(srcRec.Stroke.Color);
                MainShape.StrokeDashArray = srcRec.Stroke.vmlDashStyle;
                MainShape.Stroke.Opacity = srcRec.Stroke.Opacity;
                MainShape.StrokeLineJoin = srcRec.Stroke.vmlJoinStyle;
                MainShape.Stroke = new StrokeLineStyleBuilder().vmlRecLineStyle(srcRec);
            }
            if (srcRec.Fill != null)
            {
                MainShape.Fill = new FillBuilder().CreatevmlFill(srcRec); ;
            }
            if (srcRec.Shadow != null)
            {
                //Shadow
                DropShadowBitmapEffect dps = new DropShadowBitmapEffect();
                //dps.SetValue(NameProperty, "dps");
                dps.Softness = 0.1;
                dps.Noise = 0;
                dps.Opacity = srcRec.Shadow.Opacity;
                dps.ShadowDepth = srcRec.Shadow.ShadowDepth;
                dps.Direction = 135;
                dps.Color = srcRec.Shadow.Color;
                MainShape.BitmapEffect = dps;

            }
            if (srcRec.GetType() == typeof(vmlRoundrect))
            {
                /// The came arc is symmetry
                MainShape.RadiusX = (srcRec as vmlRoundrect).CornerRadius;
                MainShape.RadiusY = (srcRec as vmlRoundrect).CornerRadius;
            }
            

            return MainShape;
        }
        public Ellipse CreateEllipse(vmlModel.Entities.vmlOval srcOval)
        {

            Ellipse MainShape = new Ellipse();
            Canvas.SetTop(MainShape, srcOval.MarginTop);
            Canvas.SetLeft(MainShape, srcOval.MarginLeft);
            Canvas.SetZIndex(MainShape, srcOval.Zindex);
            MainShape.Width = srcOval.Width;
            MainShape.Height = srcOval.Height;


            MainShape.Fill = new SolidColorBrush(srcOval.FillColor);
            MainShape.Stroke = new SolidColorBrush(srcOval.StrokeColor);
            MainShape.StrokeThickness = srcOval.StrokeWeight;
            if (srcOval.Stroke != null)
            {
                if (srcOval.Stroke.LiveAtrrs.Contains("weight")) MainShape.StrokeThickness = srcOval.Stroke.Weight;
                if (srcOval.Stroke.LiveAtrrs.Contains("color")) MainShape.Stroke = new SolidColorBrush(srcOval.Stroke.Color);
                MainShape.StrokeDashArray = srcOval.Stroke.vmlDashStyle;
                MainShape.Stroke.Opacity = srcOval.Stroke.Opacity;
                MainShape.StrokeLineJoin = srcOval.Stroke.vmlJoinStyle;
                MainShape.Stroke = new StrokeLineStyleBuilder().vmlRecLineStyle(srcOval);
            }
            if (srcOval.Fill != null)
            {
                MainShape.Fill = new FillBuilder().CreatevmlFill(srcOval); ;
            }
            if (srcOval.Shadow != null)
            {
                //Shadow
                DropShadowBitmapEffect dps = new DropShadowBitmapEffect();
                //dps.SetValue(NameProperty, "dps");
                dps.Softness = 0.1;
                dps.Noise = 0;
                dps.Opacity = srcOval.Shadow.Opacity;
                dps.ShadowDepth = srcOval.Shadow.ShadowDepth;
                dps.Direction = 135;
                dps.Color = srcOval.Shadow.Color;
                MainShape.BitmapEffect = dps;

            }
            return MainShape;
        }

   
     }
}
   